package org.apache.flink.runtime.resourceconsumer;

import java.util.UUID;

import javax.annotation.Nullable;

import org.apache.flink.util.AbstractID;

/**
 * @类名: ConsumerMasterId
 * @说明: 消费者master Id
 *
 * @author   leehom
 * @Date	 2024年8月18日 下午4:04:29
 * 修改记录：
 *
 * @see 	 
 */
public class ConsumingMasterId extends AbstractID {

    private static final long serialVersionUID = -933276753644003754L;

    /** Creates a ConsumerMasterId that takes the bits from the given UUID. */
    public ConsumingMasterId(UUID uuid) {
        super(uuid.getLeastSignificantBits(), uuid.getMostSignificantBits());
    }

    /** Generates a new random JobMasterId. */
    private ConsumingMasterId() {
        super();
    }

    /** Creates a UUID with the bits from this JobMasterId. */
    public UUID toUUID() {
        return new UUID(getUpperPart(), getLowerPart());
    }

    /** Generates a new random JobMasterId. */
    public static ConsumingMasterId generate() {
        return new ConsumingMasterId();
    }
    
    public static ConsumingMasterId fromUuid(UUID uuid) {
        return new ConsumingMasterId(uuid);
    }

    /**
     * If the given uuid is null, this returns null, otherwise a JobMasterId that corresponds to the
     * UUID, via {@link #JobMasterId(UUID)}.
     */
    public static ConsumingMasterId fromUuidOrNull(@Nullable UUID uuid) {
        return uuid == null ? null : new ConsumingMasterId(uuid);
    }
}
